
namespace EveIntel.API.Base
{
    using System;
    using Enums;
    using Interfaces;

    /// <summary>
    /// Abstract intel provider base class
    /// </summary>
    public abstract class IntelProviderBase : IIntelProvider
    {
        private readonly Guid _uid = Guid.Empty;

        protected IntelProviderBase(Guid guid)
        {
            _uid = guid;
        }
        /// <summary>
        /// Obtains a data provider description
        /// </summary>
        public abstract string Description { get; }
        /// <summary>
        /// Obtains the provider unique id.
        /// </summary>
        public virtual Guid UniqueId { get { return _uid;  } }
        /// <summary>
        /// Determines if the data provider can handle a type of intel request
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public abstract bool CanProvideIntel(IntelTypeEnum type);
        /// <summary>
        /// Obtains the URI to navigate to
        /// </summary>
        /// <param name="type">The IntelTypeEnum value</param>
        /// <param name="args">Additional arguments needed to build the uri</param>
        /// <returns></returns>
        public abstract Uri GetUri(IntelTypeEnum type, string[] args);

        public bool Equals(IntelProviderBase other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other._uid.Equals(_uid);
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. </param><filterpriority>2</filterpriority>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (IntelProviderBase)) return false;
            return Equals((IntelProviderBase) obj);
        }

        /// <summary>
        /// Serves as a hash function for a particular type. 
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            return _uid.GetHashCode();
        }

        public static bool operator ==(IntelProviderBase left, IntelProviderBase right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(IntelProviderBase left, IntelProviderBase right)
        {
            return !Equals(left, right);
        }
    }
}